'''
    单行查询和多行查询
'''
import pymysql
try:
    myconn = pymysql.connect(host='localhost', port=3306, db='shuoGG', user='root', password='ut123456', charset='utf8mb4')
    sql = 'select * from student'
    cur = myconn.cursor() 
    cur.execute(sql)
    result1 = cur.fetchone()         # 查询第1条, 返回一个元组, cur指针自动指向下一条数据
    print(result1)                   # ('小明', 1)              
    result2 = cur.fetchone()         # 查询第2条, 返回一个元组, cur指针自动指向下一条数据
    print(result2)                   # ('小红', 0)
    result3 = cur.fetchone()         # 查询第3条, 返回一个元组, cur指针自动指向下一条数据
    print(result3)                   # ('小刚', 1)
    result4 = cur.fetchone()         # 查询第4条, 若没有数据了就返回None
    print(result4)                   # None

    cur.execute(sql)
    resultmulti = cur.fetchall()    # 返回所有的数据, 元组中嵌套元组
    print(resultmulti)              # (('小明', 1), ('小红', 0), ('小刚', 1))

    cur.close()
    myconn.close()

except Exception as e:
    print(e.message)
